<template>
  <div class="bottom-menu">
    <checkbutton class="select-all" @checkBtnClick="checkBtnClick" :isChecked="isSelectAll"></checkbutton>
    <span>全选</span>
    <span class="total-price">合计:{{cartListss}}</span>
    <span class="buy-product" @click="calcClick">去计算({{countlist}})</span>
  </div>
</template>

<script>
import checkbutton from "components/common/clickbutton/checkButton";

import { mapGetters } from "vuex";

export default {
  name: "CartBottomBar",
  data() {
    return {
      iteminfo: {
        type: Object,
        default() {
          return {};
        }
      },
      carlist: []
    };
  },
  props: {},
  components: {
    checkbutton
  },
  methods: {
    calcClick() {},
    checkBtnClick() {
      console.log("全选")
      this.carlist = this.$store.state.cartList;
      if(this.isSelectAll){
        this.$store.commit("alltrue")

      }else{
        this.$store.commit("allfalse");
      }
    }
  },
  computed: {
    ...mapGetters(["cartList"]),

    //算出所有商品的内容
    cartListss() {
      let nun = 0;
      // console.log(this.iteminfo.iid);
      this.carlist = this.$store.state.cartList;
      console.log(this.carlist);
      for (let i = 0; i < this.carlist.length; i++) {
        if (this.carlist[i].ckecked == true) {
          nun = nun + this.carlist[i].price * this.carlist[i].count;
        }
        console.log(nun);
      }
      return "￥" + nun.toFixed(2);
    }, //算出所有的数量
    countlist() {
      let nun = 0;
      this.carlist = this.$store.state.cartList;
      for (let i = 0; i < this.carlist.length; i++) {
        if (this.carlist[i].ckecked == true) {
          nun = nun + this.carlist[i].count;
        }
      }
      return nun;
    },
    isSelectAll() {
      //判断是否是全部选中
      this.carlist = this.$store.state.cartList;
      for (let i = 0; i < this.carlist.length; i++) {
        if (this.carlist[i].ckecked == false) {
          return false;
        }
      }
      return true;
    }
  }
};
</script>

<style scoped>
/* .bottom-menu{
    width: 100%;
    position: fixed;
    bottom: 50px;
    background-color: #eee;
    display: flex;

    height: 40px;
    line-height: 40px;
  }

  .check-content{
      display: flex;
      align-items: center;
      margin-left: 10px;
  }
  .check-button {
      width: 20px;
      height: 20px;
      line-height: 20px;
      margin-right: 5px;
  }
  .price {
    margin-left: 15px;
    font-size: 16px;
    color: #666;
  } */

.bottom-menu {
  width: 100%;
  height: 44px;
  background-color: #eee;
  position: fixed;
  bottom: 49px;
  left: 0;
  box-shadow: 0 -2px 3px rgba(0, 0, 0, 0.2);
  font-size: 14px;
  color: #888;
  line-height: 44px;
  padding-left: 35px;
  box-sizing: border-box;
}

.bottom-menu .select-all {
  position: absolute;
  line-height: 0;
  left: 12px;
  top: 13px;
}

.bottom-menu .total-price {
  margin-left: 15px;
  font-size: 16px;
  color: #666;
}

.bottom-menu .buy-product {
  background-color: orangered;
  color: #fff;
  width: 100px;
  height: 44px;
  text-align: center;
  line-height: 44px;
  float: right;
}
</style>